package com.sidianzhong.sdz.service.impl;

import com.github.pagehelper.PageHelper;
import com.sidianzhong.sdz.mapper.WebInspectionrecordMapper;
import com.sidianzhong.sdz.mapper.WebStationmaterialsMapper;
import com.sidianzhong.sdz.model.WebInspectionrecord;
import com.sidianzhong.sdz.model.WebInspectionrecordExample;

import com.sidianzhong.sdz.model.WebStationmaterials;
import com.sidianzhong.sdz.model.WebStationmaterialsExample;
import com.sidianzhong.sdz.service.WebStationmaterialsService;
import com.sidianzhong.sdz.utils.PageInfo;
import com.sidianzhong.sdz.utils.Tools;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


/**
* Created by hxgqh on 2016/1/7.
*/
@Service
@Transactional
public class WebStationmaterialsServiceImpl implements WebStationmaterialsService {
    protected static final Logger LOG = LoggerFactory.getLogger(WebStationmaterialsServiceImpl.class);

    // 将所有的modelMapper注入
    @Autowired
    private WebStationmaterialsMapper webStationmaterialsMapper;


    @Override
    public WebStationmaterials create(WebStationmaterials item) {

        webStationmaterialsMapper.insert(item);
         return item;
    }

    @Override
    public int delete(Integer id) {
        return webStationmaterialsMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int update(WebStationmaterials item) {

        return webStationmaterialsMapper.updateByPrimaryKeySelective(item);
    }

    @Override
    public WebStationmaterials get(Integer id) {
        return webStationmaterialsMapper.selectByPrimaryKey(id);
    }

    @Override
    public PageInfo<WebStationmaterials> getListWithPaging(Integer pageNum, Integer pageSize,
                                                           String sortItem, String sortOrder,WebStationmaterials item){

        WebStationmaterialsExample  example = new WebStationmaterialsExample();
        WebStationmaterialsExample.Criteria criteria = example.createCriteria();
        if (item.getMaterialname()!=null){
            criteria.andMaterialnameLike("%"+item.getMaterialname()+"%");
        }
        if (item.getMaterialtype()!=null){
            criteria.andMaterialtypeEqualTo(item.getMaterialtype());
        }
        if (item.getEquipmenttypekey()!=null){
            criteria.andEquipmenttypekeyEqualTo(item.getEquipmenttypekey());
        }
        if(item.getEquipmentkey() != null ){
            criteria.andEquipmentkeyEqualTo(item.getEquipmentkey());
        }
        if (item.getSubtype()!=null){
            criteria.andSubtypeEqualTo(item.getSubtype());
        }

        example.setOrderByClause(Tools.humpToLine(sortItem)+" "+sortOrder);
        PageHelper.startPage(pageNum, pageSize);
        List< WebStationmaterials> list = this.webStationmaterialsMapper.selectByExample(example);
        PageInfo result = new PageInfo(list);

        return result;

    }


}
